import { REGEX_SORT, REGEX_POSITIVE_INTEGER } from '@/utils/validate'

const validatorTotal = (rule, value, callback) => {
  if (value < 5 || value > 50000) {
    return callback(new Error('礼品券总张数在（5-50000）之间！'))
  } else if (!REGEX_POSITIVE_INTEGER.test(value)) {
    return callback(new Error('请输入正整数！'))
  }
  callback()
}

const rules = {
  name: [
    {
      required: true,
      message: '请输入礼品券名称',
      trigger: 'blur'
    },
    {
      min: 1,
      max: 15,
      message: '限制输入1-15字',
      trigger: 'blur'
    }
  ],
  prefix: [
    {
      required: true,
      message: '请输入礼品券开头',
      trigger: 'blur'
    },
    {
      pattern: /^[A-Z]+$/,
      message: '礼品券仅限大写字母',
      trigger: 'blur'
    },
    {
      min: 1,
      max: 10,
      message: '限制输入1-10之间',
      trigger: 'blur'
    }
  ],
  total: [
    {
      required: true,
      message: '请输入礼品券总张数',
      trigger: 'blur'
    },
    {
      validator: validatorTotal,
      trigger: 'blur'
    }
  ],
  sort: [
    {
      required: true,
      message: '请输入排序',
      trigger: 'blur'
    },
    {
      pattern: REGEX_SORT,
      message: '请输入1-9999'
    }
  ],
  giftCouponConfigBackPos: [
    {
      type: 'array',
      required: true,
      message: '请添加奖品',
      trigger: 'change'
    }
  ],
  notPrizeRemind: [
    {
      max: 100,
      message: '不可超过100字'
    }
  ]
}

export default rules
